package com.youan.log.modules.audit.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.youan.log.modules.audit.entity.SdAttackSuccess;
import com.youan.log.modules.audit.mapper.SdAttackSuccessMapper;
import com.youan.log.modules.audit.service.ISdAttackSuccessService;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SdAttackSuccessServiceImpl extends ServiceImpl<SdAttackSuccessMapper, SdAttackSuccess> implements ISdAttackSuccessService {

    @Autowired
    private SdAttackSuccessMapper sdAttackSuccessMapper;

    @Override
    public IPage<SdAttackSuccess> getPageGroupByAttackCity(IPage<SdAttackSuccess> page, SdAttackSuccess sdAttackSuccess) {
        page.setRecords(sdAttackSuccessMapper.getPageGroupByAttackCity(page, sdAttackSuccess));
        return page;
    }

    @Override
    public List<SdAttackSuccess> detail(SdAttackSuccess sdAttackSuccess) throws Exception {
        if(ObjectUtils.isEmpty(sdAttackSuccess.getDate())) {
            throw new Exception("参数错误：缺少日期参数！");
        }
        if(StringUtils.isEmpty(sdAttackSuccess.getAttackCity())) {
            throw new Exception("参数错误：缺少发起攻击城市！");
        }
        LambdaQueryWrapper<SdAttackSuccess> sdAttackSuccessLqw = new LambdaQueryWrapper<SdAttackSuccess>()
                .eq(SdAttackSuccess::getDate, sdAttackSuccess.getDate()).eq(SdAttackSuccess::getAttackCity, sdAttackSuccess.getAttackCity())
                .orderByDesc(SdAttackSuccess::getAttackNum);
        return list(sdAttackSuccessLqw);
    }
}
